home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / freeli20.zip / progs / showgy.asm < prev    next >
Assembly Source File  |  1996-07-01  |  5KB  |  159 lines

  1. ; SHOWGY:  Display *.GY files, resolution enhanced
  2.  
  3. ; *.GY are grayscale files that are 160x100 in raw
  4. ; 8-bit format.  Two examples are provided.
  5.  
  6. Ideal
  7. Jumps
  8.  
  9. Public      main
  10. Extrn       startup:near
  11.  
  12. Macro       lcall p,a,b,c,d,e,f,g,h ;; library call
  13.  
  14.             ifnb <a>
  15.               push a                ;; if args, push first arg
  16.               lcall p,b,c,d,e,f,g,h ;; and recurse . . .
  17.             else
  18.               extrn p:near          ;; declare procedure
  19.               call p                ;; call procedure
  20.             endif
  21.  
  22. EndM
  23.  
  24. Model Tiny
  25. CodeSeg
  26. P186
  27. Org 100h
  28.  
  29. Start:      jmp startup
  30.  
  31. ;****************** Data Section
  32.  
  33. Syntax      db 'Syntax:  SHOWGY <gy-file>',13,10,0
  34.  
  35. ;****************** 'main' procedure
  36.  
  37. Proc        main
  38.  
  39.             test cx,cx              ;No arguments?
  40.             jz m_syntax
  41.  
  42.             lcall fopen [di],0      ;Open the file
  43.             test ax,ax              ;File not found?
  44.             jz m_syntax
  45.  
  46.             xchg bp,ax              ;BP = handle
  47.  
  48.             lcall initgraph 0       ;Init 320x200 mode
  49.             lcall setgwin 0,0,318,198 ;Set graphics window
  50.  
  51. ;-----------------------------------------------------------
  52. ; Set grayscale palette:  64 grays mapped to 256 colors
  53. ;-----------------------------------------------------------
  54.  
  55.             mov dx,03C8h            ;Set up for palette
  56.             xor al,al               ;write operation
  57.             out dx,al
  58.             inc dx
  59.  
  60. m_pal:      mov cx,12               ;4 regs at a time
  61. m_pal2:     out dx,al               ;Send gray value
  62.             loop m_pal2             ;Loop back
  63.  
  64.             inc ax                  ;Next shade
  65.             test al,40h             ;Loop while < 64
  66.             jz m_pal
  67.  
  68. ;-----------------------------------------------------------
  69. ; Put the defined pixels on the screen, separated by 1
  70. ;-----------------------------------------------------------
  71.  
  72.             xor cx,cx               ;Zero row counter
  73. m_oloop1:   xor dx,dx               ;Zero column counter
  74. m_iloop1:   lcall fgetc bp          ;Get byte
  75.             lcall setgcolor ax      ;Set color
  76.             lcall putpix dx,cx      ;Put pixel
  77.  
  78.             inc dx                  ;Next column
  79.             inc dx
  80.             cmp dx,320              ;Loop back
  81.             jb m_iloop1 
  82.  
  83.             inc cx                  ;Next row
  84.             inc cx
  85.             cmp cx,200              ;Loop back
  86.             jb m_oloop1
  87.  
  88. ;-----------------------------------------------------------
  89. ; Now, interpolate to the other 3/4 of the pixels
  90. ;-----------------------------------------------------------
  91.  
  92.             xor cx,cx               ;Zero row counter
  93. m_oloop2:   xor dx,dx               ;Zero column counter
  94.  
  95. m_iloop2:   lcall getpix dx,cx      ;Get average of 2 horizontal pixels
  96.             xchg bx,ax
  97.             push bx
  98.             inc dx
  99.             inc dx
  100.             lcall getpix dx,cx
  101.             add bx,ax
  102.             shr bx,1
  103.             dec dx                  ;Put this pixel in the middle
  104.             lcall setgcolor bx
  105.             lcall putpix dx,cx
  106.             dec dx
  107.  
  108.             pop bx                  ;Get average of 2 vertical pixels
  109.             inc cx
  110.             inc cx
  111.             lcall getpix dx,cx
  112.             add bx,ax
  113.             push bx
  114.             shr bx,1
  115.             dec cx                  ;Put this pixel in the middle
  116.             lcall setgcolor bx
  117.             lcall putpix dx,cx
  118.             dec cx
  119.  
  120.             pop bx                  ;Restore vertical count
  121.             inc dx                  ;Get average of all 4 pixels
  122.             inc dx
  123.             lcall getpix dx,cx
  124.             add bx,ax
  125.             inc cx
  126.             inc cx
  127.             lcall getpix dx,cx
  128.             add bx,ax
  129.             shr bx,2
  130.             dec cx                  ;Put this pixel in the middle
  131.             dec dx
  132.             lcall setgcolor bx
  133.             lcall putpix dx,cx
  134.             dec cx
  135.  
  136.             inc dx                  ;Next column
  137.             cmp dx,320              ;Loop back
  138.             jb m_iloop2 
  139.  
  140.             inc cx                  ;Next row
  141.             inc cx
  142.             cmp cx,200              ;Loop back
  143.             jb m_oloop2
  144.  
  145.             xor ah,ah               ;Wait for a key
  146.             int 16h
  147.  
  148.             lcall closegraph        ;Return to text mode
  149.             lcall fclose bp         ;Close file
  150.             ret                     ;Return
  151.  
  152. m_syntax:   push offset(Syntax)     ;Print syntax message
  153.             lcall puts
  154.             ret                     ;Return
  155.  
  156. EndP        main
  157.  
  158. End Start
  159.